/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.dsw2.escuela.dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mx.its.dsw2.escuela.modelo.Alumno;

/**
 *
 * @author Maq-8
 */
@Stateless
public class AlumnoDao extends AbstractDao<Alumno> implements AlumnoDaoLocal {
    @PersistenceContext(unitName = "Escuela-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public AlumnoDao() {
        super(Alumno.class);
    }

    @Override
    public boolean findByDuplicity(Alumno student) {
       Query q = em.createNamedQuery("Alumno.findByDuplicity");
        q.setParameter("nombre", student.getNombre());
        q.setParameter("aMaterno", student.getAMaterno());
        q.setParameter("aPaterno", student.getAPaterno());
        return !q.getResultList().isEmpty();
    }

    @Override
    public Alumno findStudentForAssistance(String noControl) {
        Query q = em.createNamedQuery("Alumno.findByNocontrol");
        q.setParameter("nocontrol", noControl);
        if (!q.getResultList().isEmpty()) {
            return (Alumno) q.getResultList().get(0);
        } else {
            return null;
        }
    }
    
    
    
}
